package com.itheima.dao.impl;

import com.itheima.dao.BookDao;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.*;

//@Component("bookDao")
@Repository
//@Scope设置bean的作用范围,设置为非单例
//prototype非单例, singleton单例
//@Scope("prototype")
public class BookDaoImpl implements BookDao {
    /*private BookDaoImpl(){
        System.out.println("book dao constructor is running....");
    }*/
    /*public void save() {
        System.out.println("book dao save ...");
    }*/

    /*//表示bean初始化对应的操作
    public void init(){
        System.out.println("init ....");
    }
    //表示bean销毁前对应的操作
    public void destory(){
        System.out.println("destory ....");
    }*/

    /*//声明对应的简单数据类型属性，并提供对应的setter方法
    private String databaseName;
    private int connectionNum;
    public void setConnectionNum(int connectionNum){
        this.connectionNum = connectionNum;
    }
    public void setDatabaseName(String databaseName){
        this.databaseName = databaseName;
    }
    public void save(){
        System.out.println("book dao save..." + databaseName+","+connectionNum);
    }*/

    //构造器方法注入
   /* private String datebaseName;
    private int connectionNum;
    public void save(){
        System.out.println("book dao save...");
    }*/

    /*//添加多个简单属性并提供构造方法
    private String databaseName;
    private int connectionNum;
    public BookDaoImpl(String databaseName,int connectionNum){
        this.databaseName = databaseName;
        this.connectionNum = connectionNum;
    }
    public void save(){
        System.out.println("book dao save..."+databaseName+","+connectionNum);
    }*/

   /* private String datebaseName;
    private int connectionNum;
    public void save(){
        System.out.println("book dao save...");
    }*/
/*
    //集合注入
    private int[] array;
    private List<String> list;
    private Set<String> set;
    private Map<String,String> map;
    private Properties properties;
    public void save(){
        System.out.println("book dao save ...");
        System.out.println("遍历数组:"+ Arrays.toString(array));
        System.out.println("遍历List" + list);
        System.out.println("遍历Set" + set);
        System.out.println("遍历Map" + map);
        System.out.println("遍历Properties" + properties);
    }

    public void setArray(int[] array) {
        this.array = array;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    public void setSet(Set<String> set) {
        this.set = set;
    }

    public void setMap(Map<String, String> map) {
        this.map = map;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }*/

 /*   //实现Druid管理
    private String name;

    public void setName(String name) {
        this.name = name;
    }

    public void save() {
        System.out.println("book dao save ..." + name);
    }*/

    /*//读取单个属性
    private String name;
    public void setName(String name){
        this.name = name;
    }
    public void save(){
        System.out.println("book dao save ..."+name);
    }*/
/*
    //核心容器
    public void save(){
        System.out.println("book dao save ...");
    }*/

/*    //BeanFactory的使用
    public BookDaoImpl(){
        System.out.println("constructor");
    }
    public void save(){
        System.out.println("book dao save");
    }*/

   /* //注解开发
    public void save(){
        System.out.println("book dao save ...");
    }*/
/*
    //注解开发bean作用范围与生命周期
    public void save(){
        System.out.println("book dao save ...");
    }
    @PostConstruct//在构造方法之后进行，替换init-method
    public void init(){
        System.out.println("init ...");
    }
    @PreDestroy//在销毁方法之前进行，替换destroy-method
    public void destroy(){
        System.out.println("destroy ...");
    }*/

    //注解开发依赖注入
    /*public void save(){
        System.out.println("book dao save ...");
    }*/
    //简单类型注入
    //@Value一般会被用在从properties配置文件中读取内容进行使用
    //Value为基本数据类型或字符串类型属性设置值
   /* @Value("${name}")
    private String name;
    public void save(){
        System.out.println("book dao save ..."+name);
    }*/

   /* //IOC/DI注解开发管理第三方bean
    public void save(){
        System.out.println("book dao save ...");
    }*/

    /*//AOP入门案例
    public void save(){
        System.out.println(System.currentTimeMillis());
        System.out.println("book dao save ...");
    }
    public void update(){
        System.out.println("book dao update ...");
    }*/

    /*//AOP通知类型
    public void update(){
        System.out.println("book dao update is running...");
    }
    public int select(){
        System.out.println("book dao select is running ...");
        return 100;
    }*/

    //AOP通知获取数据
    public String findName(int id,String password){
        System.out.println("id:"+id);
        if (true){
            throw new NullPointerException();
        }
        return "itcast";
    }
}